package com.menu {
	import org.flash.net.URL;
	
	import flash.events.ContextMenuEvent;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;

	/** var menu:MyContextMenu = new MyContextMenu();
		menu.addCustomMenuItem("版本号：v12.4.10","http://hao123.com");
		menu.addCustomMenuItem("版本号：v12.4.11","http://hao123.com");
		this.contextMenu = menu.getVersionMenu(); 
	*/
	public class MyContextMenu {
		private var menu:ContextMenu;
		
		public function MyContextMenu(){
			menu = new ContextMenu();
			menu.hideBuiltInItems();
		}

		/**
		 * 定义版菜单项
		 */
		public function getVersionMenu():ContextMenu {
			var version:ContextMenuItem = new ContextMenuItem(Version.version, true);
			menu.customItems.push(version);
			version.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, itemSelectHandler);
			return menu;
		}

		private function itemSelectHandler(e:ContextMenuEvent):void {
			URL.goToURL(Version.versionUrl, URL.BLANK);
		}

		/**添加自定项*/
		public function addCustomMenuItem(label:String,url:String):void {
			var url:String = url;
			var item:ContextMenuItem = new ContextMenuItem(label, true);
			menu.customItems.push(item);
			item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, function(e:ContextMenuEvent):void{
				URL.goToURL(url);
			});
		}

		private function removeMenu():void {
		}
	}
}